package com.jianganming.singleton;

import java.util.Objects;

/**
 * 懒汉式
 * 特点：第一次调用才初始化，避免内存浪费
 */
public class Singleton2 {
    private static Singleton2 singleton;
    public static synchronized Singleton2 getInstance(){
        if(Objects.isNull(singleton)){
            singleton = new Singleton2();
        }
        return singleton;
    }

    public static void main(String[] args) {
        Singleton2 instance = Singleton2.getInstance();
        Singleton2 instance1 = Singleton2.getInstance();
        System.out.println(instance==instance1);
    }
}
